/**
 * Copyright (c) 2011-2012
 * OmniCore CodeGuide
 */

package de.tum.in.oose.bumpers.cars.instruments;

import de.tum.in.oose.bumpers.cars.UserCar;

/**
 * Adapter for the AnalogSpeedomenter instrument.
 */
public class AnalogSpeedometerAdapter extends Instrument{
	
	private static final long serialVersionUID = 1L;
	private AnalogSpeedometer speedometer;
	private int speed;
	
	/**
	 * Constructor for creating the AnalogSpeedomenterAdapter for a given car and a speedometer.
	 * @param theCar The car which speed information will be shown. 
	 * @param speedometer The used speedometer instrument.
	 */
	public AnalogSpeedometerAdapter(UserCar theCar,
									AnalogSpeedometer speedometer){
		super(theCar);
		this.speedometer = speedometer;
		updateInstrument();
	}
	
	/**
	 * Updates the AnalogSpeedometer instrument depending on changes of the car's speed.
	 */
	public void updateInstrument() {
		if(this.speed != getTheCar().getSpeed()){
			this.speed = getTheCar().getSpeed();
			
			double percent = (double)getTheCar().getMaxSpeed()/100*this.speed;
			int angle = (int)(speedometer.getMaxAngle()*percent);
			this.speedometer.setAngle(angle);
		}
	}
	
	
}

